<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
	<title>基础数据-供应商管理</title>
	<meta charset="utf-8">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>libs/bootstrap-3.3.7-dist/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/reset.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/style.css">
	<link rel="stylesheet" type="text/css" href="<%=basePath %>css/iframe.css">
</head>
<body>
	<div id="mainContent">
		<div  id="mainContent_content">
			<div class="page_header"><a>供应商管理</a></div>
			<div class="search">
				<form class="form-search" method="post" action="<%=basePath %>${page.pageUrl }" class="form">
					<label>供应商代码</label>
					<input type="text" name="suppliercode" value="${page.suppliercode }" class="form-control"></input>
					<label>供应商名称</label>
					<input type="text" name="suppliername" value="${page.suppliername }" class="form-control"></input>
					<label>状态</label>
					<select name="supplierstatus" class="form-control select">
						<option value="">全部</option>
						<option value="可用" ${page.supplierstatus=="可用"?"selected":"" }>可用</option>
						<option value="不可用" ${page.supplierstatus=="不可用"?"selected":"" }>不可用</option>
					</select>
					<input type="submit" value="查询" class="btn btn1"></input>
				</form>
			</div>
			<div class="btn">				
				<c:if test="${isAdd }">
					<input type="button" value="新增" onclick="addSupplier();" class="btn btn1"></input>
				</c:if>
				<input type="button" value="编辑" onclick="toEditSupplier();" class="btn btn2"></input>
				<input type="button" value="查看附件" onclick="toShowSupplierAnnex();" class="btn btn1"></input>
				<c:if test="${isDelete }">
					<input type="button" value="删除" onclick="toDeleteSupplier();" class="btn btn_danger"></input>
				</c:if>
			</div>
			<div class="tableBox box">
				<table class="table table-bordered table_text_center">
					<thead>
						<tr>
							<th></th>
							<th style="width:200px;">操作</th>
							<th>供应商代码</th>
							<th>供应商名称</th>
							<th>状态</th>
							<th>创建时间</th>
							<th>创建人</th>
						</tr>
					</thead>
					<tbody>
						<c:forEach items="${supplierList }" var="supplier" varStatus="i">
							<tr onclick="selectRow(this);">
								<td><label class="radio"><input type="radio" name="operateSupplier" value="${supplier.supplierid }"><span class="radio_icon"></span></label></td>
								<td>
									<a class="btn btn-xs btn2" onclick="editSupplier(${supplier.supplierid });">编辑</a>
									<a class="btn btn-xs btn1" onclick="showSupplierAnnex(${supplier.supplierid });">附件</a>
									<c:if test="${isDelete }">
										<a class="btn btn-xs btn_danger" onclick="confirmDeleteSupplier(${supplier.supplierid });">删除</a>
									</c:if>
								</td>
								<td>${supplier.suppliercode }</td>
								<td>${supplier.chinesename }</td>
								<td>${supplier.status }</td>
								<td><fmt:formatDate value="${supplier.createtime }"
										type="both" /></td>
								<td>${supplier.createpersonname }</td>
							</tr>
						</c:forEach>
					</tbody>
				</table>
			</div>
			<jsp:include page="/jsp/basic/page.jsp"></jsp:include>
		</div>
		<jsp:include page="/jsp/basicData/supplierManage/addSupplier.jsp"></jsp:include>
		<jsp:include page="/jsp/basicData/supplierManage/editSupplier.jsp"></jsp:include>
		<jsp:include page="/jsp/basicData/supplierManage/annex.jsp"></jsp:include>
		<jsp:include page="/jsp/basic/prompt.jsp"></jsp:include>
	</div>
	<script src="<%=basePath %>js/jquery-3.2.1.min.js"></script>
	<script src="<%=basePath %>libs/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
	<script src="<%=basePath %>js/public.js"></script>
	<script type="text/javascript">
		function selectRow(obj){
			$(obj).find('input:radio[name="operateSupplier"]')[0].checked=true;
		}
		
		function toEditSupplier(){
			var radio=$('input:radio[name="operateSupplier"]:checked');
			if(!radio.val()){
				Prompt.alert("提示","请先选中需要编辑的供应商！");
				return;
			}
			editSupplier(radio.val());
		}
		
		function toShowSupplierAnnex(){
			var radio=$('input:radio[name="operateSupplier"]:checked');
			if(!radio.val()){
				Prompt.alert("提示","请先选中需要查看附件的供应商！");
				return;
			}
			showSupplierAnnex(radio.val());
		}
		
		function toDeleteSupplier(){
			var radio=$('input:radio[name="operateSupplier"]:checked');
			if(!radio.val()){
				Prompt.alert("删除提示","请先选中需要删除的供应商！");
				return;
			}
			confirmDeleteSupplier(radio.val());
		}
			
		function confirmDeleteSupplier(id){
			var delFunc=function(){
				$.ajax({
					url:"<%=basePath %>supplier/delete.do",
					type:"post",
					async : false,
					dataType:"json",
					data : "supplierid="+id,
					success:function(data){
						if(data.result=="success"){
							Prompt.alert("删除提示","供应商已删除！",Prompt.refresh);
						}
					},
					error :function(){
						Prompt.alert("删除提示","服务器无响应，请刷新页面后重试！");
					}
				});
			}
			Prompt.confirm("提示","确认要删除该供应商吗?删除后无法恢复",delFunc);
		}
		
		/*加载省下拉选*/  
		function loadProvince(obj,target,value) {  
            $(target).html("");  
            $(target).append("<option value=''>" + '请选择' + "</option>");  
            var nationality_id=$(obj).val();
		    $.ajax({  
		        type: "post",  
				async : false,
		        url: "<%=basePath %>area/getProvince.do",  
		        data: {"id": nationality_id},  
		        success: function (data) {
		            for (var i = 0; i < data.length; i++) {  
		                $(target).append("<option value='" + data[i].provincecityid + "' >" + data[i].provincecityname + "</option>");  
		            }
		            if(value){
		            	$(target).val(value);
		            }
		        } 
		    });  
		}  

		/*加载市下拉选*/  
		function loadCity(obj,target,value) {  
            $(target).html("");  
            $(target).append("<option value=''>" + '请选择' + "</option>");  
            var province_id=$(obj).val();
		    $.ajax({  
		        type: "post",  
				async : false,
		        url: "<%=basePath %>area/getCity.do",  
		        data: {"id": province_id},  
		        success: function (data) {
		            for (var i = 0; i < data.length; i++) {  
		                $(target).append("<option value='" + data[i].provincecityid + "' >" + data[i].provincecityname + "</option>");  
		            }
		            if(value){
		            	$(target).val(value);
		            }
		        } 
		    });  
		} 

	</script>
</body>
</html>